//
//  HNSH_OpenRedMessageCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/8/12.
//

#import "HNSH_OpenRedMessageCell.h"
#import "HNSH_OpenContent.h"

@interface HNSH_OpenRedMessageCell ()

/* iconImgV */
@property (nonatomic, strong) UIImageView *iconImgV;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;

@end

@implementation HNSH_OpenRedMessageCell

#pragma mark - Cycle Methods
+ (CGSize)sizeForMessageModel:(RCMessageModel *)model
      withCollectionViewWidth:(CGFloat)collectionViewWidth
         referenceExtraHeight:(CGFloat)extraHeight{
    return CGSizeMake(collectionViewWidth, extraHeight + 20);
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.baseContentView.mas_centerX).offset(10);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.desLabel.mas_left).offset(-6);
        make.centerY.equalTo(self.desLabel.mas_centerY);
        make.width.mas_equalTo(13);
        make.height.mas_equalTo(16);
    }];

}

- (void)setModel:(RCMessageModel *)model{
    [super setModel:model];
    
    HNSH_OpenContent * con = (HNSH_OpenContent *)model.content;
    
    NSString *firstString = [con.openUserId isEqualToString:[ST_UserManager shareInstance].rcUser.uid] ? @"你" : con.openUsername;
    NSString *secondString = [con.packetUserId isEqualToString:[ST_UserManager shareInstance].rcUser.uid] ? @"你" : con.packetUsername;
    self.desLabel.text = [NSString stringWithFormat:@"%@领取了%@的红包",firstString,secondString];
    self.desLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.desLabel.text SelectContent:@"红包" CommonFont:self.desLabel.font SpeFont:self.desLabel.font Color:[UIColor colorWithHexString:@"#FC972E"]];
}

- (void)addAllViews {
    [self.baseContentView addSubview:self.iconImgV];
    [self.baseContentView addSubview:self.desLabel];
}

- (void)gesAction{
//    NYSendRedContent * con = (NYSendRedContent *)self.model.content;
//    if (self.delegate && [self.delegate respondsToSelector:@selector(didTapMessageCell:)]) {
//        [self.delegate didTapMessageCell:self.model];
//    }
}

#pragma mark lazy
- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        _iconImgV = [[UIImageView alloc]init];
        _iconImgV.image = [UIImage imageNamed:@"chat_qun_open_red_alert"];
    }
    return _iconImgV;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.text = @"";
        _desLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _desLabel.font = [UIFont systemFontOfSize:12];
    }
    return _desLabel;
}

@end
